import json
from collections import defaultdict
from typing import Set, List, Tuple,Dict
import logging
import os
import sys
from logging.handlers import TimedRotatingFileHandler
import requests
import time
from datetime import datetime, timedelta,time as dtime
import configparser
from functools import wraps
from DeviceManagerClient import DeviceManagerClient
result_out_file = 'result.ini'
def load_result_settings():
        # 如果配置文件不存在，使用默认值
    if not os.path.exists(result_out_file):
        return {
                'total_money': '5000',
                'init_money': '2',
                'betting_number': '',
                'betting_position': '',
                'betting_cnt': '',
                'next_spider_date': '',
                'current_issue_no': '',
                'current_open_code': '',
                'stop_time': '',
                'win_cnt': '0',
                'win_money': '0',
                'betting_money': '10',
                'all_money': '',
                'all_cnt': '',
                'win_total_count':'0'
            }

    config = configparser.ConfigParser()
    config.read(result_out_file)

    # 返回配置字典，如果某个键不存在则使用默认值
    return {
            'total_money': config.get('RESULT', 'total_money', fallback='600'),
            'init_money': config.get('RESULT', 'init_money', fallback='10'),
            'betting_number': config.get('RESULT', 'betting_number', fallback=''),
            'betting_position': config.get('RESULT', 'betting_position', fallback=''),
            'betting_cnt': config.get('RESULT', 'betting_cnt', fallback='0'),
            'next_spider_date': config.get('RESULT', 'next_spider_date', fallback=''),
            'current_issue_no': config.get('RESULT', 'current_issue_no', fallback=''),
            'current_open_code': config.get('RESULT', 'current_open_code', fallback=''),
            'stop_time': config.get('RESULT', 'stop_time', fallback=''),
            'win_cnt': config.get('RESULT', 'win_cnt', fallback='0'),
            'win_money': config.get('RESULT', 'win_money', fallback='0'),
            'betting_money': config.get('RESULT', 'betting_money', fallback='0'),
            'all_money': config.get('RESULT', 'all_money', fallback='0'),
            'all_cnt': config.get('RESULT', 'all_cnt', fallback='0'),
            'win_total_count': config.get('RESULT', 'win_total_count', fallback='0')
    }
def parse_betting_num(betting_str: str) -> Dict[str, str]:
    """解析押注号码映射配置"""
    betting_map = {}
    pairs = betting_str.split(',')
    for pair in pairs:
        key, value = pair.split(':')
        betting_map[key] = value
    return betting_map

if __name__ == "__main__":
    open_code = '0,3,2,3,4'.split(',')
    ccc =   '9,3,2,3,4'.split(',')

    betting_map = parse_betting_num('0:9,1:3,2:5,3:7,4:1,5:9,6:3,7:5,8:7,9:1')
    result = [betting_map.get(open_code[0]), betting_map.get(open_code[1]), betting_map.get(open_code[2]), betting_map.get(open_code[3]), betting_map.get(open_code[4])]
    match_count = match_count = sum(1 for a, b in zip(ccc, result) if a == b)
    print(match_count)